///////////////////////////////////////////////////////////////////////////////
group { name: "elm/segment_control/base/default";
   #define SEGMENT_TYPE_SINGLE 1
   #define SEGMENT_TYPE_LEFT 2
   #define SEGMENT_TYPE_MIDDLE 3
   #define SEGMENT_TYPE_RIGHT 4
   #define SEGMENT_STATE_NORMAL 1
   #define SEGMENT_STATE_PRESSED 2
   #define SEGMENT_STATE_SELECTED 3
   #define SEGMENT_STATUS_ENABLED 0
   #define SEGMENT_STATUS_DISABLED 1
   parts {
      part { name: "bg"; type: RECT; mouse_events: 0;
         scale: 1;
         description { state: "default" 0.0;
            color: 0 0 0 0; // no cc
            min: 160 24;
         }
      }
   }
}
group { name: "elm/segment_control/item/default";
   parts {
      part { name: "segment"; type: RECT;
         scale: 1;
         description { state: "default" 0.0;
            visible: 0;
            offscale;
         }
         description { state: "default_single" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/normal/segmentcontrol/item";
            visible: 1;
         }
         description { state: "default_left" 0.0;
            inherit: "default_single" 0.0;
            visible: 1;
         }
         description { state: "default_right" 0.0;
            inherit: "default_single" 0.0;
            visible: 1;
         }
         description { state: "default_middle" 0.0;
            inherit: "default_single" 0.0;
            visible: 1;
         }
         description { state: "pressed_single" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/pressed/segmentcontrol/item";
            visible: 1;
         }
         description { state: "pressed_left" 0.0;
            inherit: "pressed_single" 0.0;
            visible: 1;
         }
         description { state: "pressed_right" 0.0;
            inherit: "pressed_single" 0.0;
            visible: 1;
         }
         description { state: "pressed_middle" 0.0;
            inherit: "pressed_single" 0.0;
            visible: 1;
         }
         description { state: "selected_single" 0.0;
            inherit: "default" 0.0;
            color_class: "/bg/selected/segmentcontrol/item";
            visible: 1;
         }
         description { state: "selected_left" 0.0;
            inherit: "selected_single" 0.0;
            visible: 1;
         }
         description { state: "selected_right" 0.0;
            inherit: "selected_single" 0.0;
            visible: 1;
         }
         description { state: "selected_middle" 0.0;
            inherit: "selected_single" 0.0;
            visible: 1;
         }
      }
      part { name: "disabler"; type: RECT;
         description { state: "default" 0.0;
            rel.to: "segment";
            color_class: "/bg/disabled/segmentcontrol/item";
            visible: 0;
         }
         description { state: "disabled" 0.0;
            inherit: "default" 0.0;
            visible: 1;
         }
      }
      part { name: "icon_disabler"; type: RECT;
         description { state: "default" 0.0;
            rel.to: "segment";
            color: 255 255 255 255; // no cc
         }
         description { state: "disabled" 0.0;
            inherit: "default" 0.0;
            color: 255 255 255 64; // no cc
         }
      }
      part { name: "elm.swallow.icon"; type: SWALLOW;
         scale: 1;
         clip_to: "icon_disabler";
         description { state: "default" 0.0;
            align: 0.0 0.5;
            rel1.offset: 0 4;
            rel2.offset: 0 -5;
            rel2.relative: 0.0 1.0;
            offscale;
         }
         description { state: "visible" 0.0;
            inherit: "default" 0.0;
            rel1.offset: 4 4;
            rel2.offset: 4 -5;
            aspect: 1.0 1.0;
            aspect_preference: VERTICAL;
            min: 16 16;
         }
         description { state: "icononly" 0.0;
            inherit: "default" 0.0;
            align: 0.5 0.5;
            rel1.offset: 4 4;
            rel2.relative: 1.0 1.0;
            rel2.offset: -5 -5;
            aspect: 1.0 1.0;
            aspect_preference: VERTICAL;
            min: 16 16;
         }
      }
      part { name: "elm.text"; type: TEXT; mouse_events: 0;
         scale: 1;
         description { state: "default" 0.0;
            fixed: 1 1;
            min: 1 1;
            rel1.to_x: "elm.swallow.icon";
            rel1.relative: 1.0 0.0;
            rel1.offset: 4 4;
            rel2.offset: -5 -5;
            color_class: "/fg/normal/segmentcontrol/item";
            text { font: FN; size: 10;
               min: 0 1;
               text_class: "button";
            }
         }
         description { state: "pressed" 0.0;
            inherit: "default" 0.0;
            color_class: "/fg/pressed/segmentcontrol/item";
         }
         description { state: "selected" 0.0;
            inherit: "default" 0.0;
            color_class: "/fg/selected/segmentcontrol/item";
         }
         description { state: "disabled" 0.0;
            inherit: "default" 0.0;
            color_class: "/fg/disabled/segmentcontrol/item";
         }
      }
   }
   programs {
      script {
         public seg_type; // Single, Left, Middle, Right.
         public seg_state; // Normal/Default, Pressed, Selected.
         public seg_status; // Enabled/Default, Disabled

         public update_state() {
            new type = get_int(seg_type);
            new state = get_int(seg_state);
            new status = get_int(seg_status);

            if (status == SEGMENT_STATUS_ENABLED) {
              set_state(PART:"disabler", "default", 0.0);
              set_state(PART:"icon_disabler", "default", 0.0);
               if (state == SEGMENT_STATE_NORMAL) {
                  if (type == SEGMENT_TYPE_SINGLE)
                    set_state(PART:"segment", "default_single", 0.0);
                  else if (type == SEGMENT_TYPE_LEFT)
                    set_state(PART:"segment", "default_left", 0.0);
                  else if (type == SEGMENT_TYPE_MIDDLE)
                    set_state(PART:"segment", "default_middle", 0.0);
                  else if (type == SEGMENT_TYPE_RIGHT)
                    set_state(PART:"segment", "default_right", 0.0);
                  set_state(PART:"elm.text", "default", 0.0);
               } else if (state == SEGMENT_STATE_PRESSED) {
                  if (type == SEGMENT_TYPE_SINGLE)
                    set_state(PART:"segment", "pressed_single", 0.0);
                  else if (type == SEGMENT_TYPE_LEFT)
                    set_state(PART:"segment", "pressed_left", 0.0);
                  else if (type == SEGMENT_TYPE_MIDDLE)
                    set_state(PART:"segment", "pressed_middle", 0.0);
                  else if (type == SEGMENT_TYPE_RIGHT)
                    set_state(PART:"segment", "pressed_right", 0.0);
                  set_state(PART:"elm.text", "pressed", 0.0);
               } else if (state == SEGMENT_STATE_SELECTED) {
                  if (type == SEGMENT_TYPE_SINGLE)
                    set_state(PART:"segment", "selected_single", 0.0);
                  else if (type == SEGMENT_TYPE_LEFT)
                    set_state(PART:"segment", "selected_left", 0.0);
                  else if (type == SEGMENT_TYPE_MIDDLE)
                    set_state(PART:"segment", "selected_middle", 0.0);
                  else if (type == SEGMENT_TYPE_RIGHT)
                    set_state(PART:"segment", "selected_right", 0.0);
                  set_state(PART:"elm.text", "selected", 0.0);
               }
            } else {
               set_state(PART:"disabler", "disabled", 0.0);
               set_state(PART:"icon_disabler", "disabled", 0.0);
               set_state(PART:"elm.text", "disabled", 0.0);
               if (type == SEGMENT_TYPE_SINGLE)
                 set_state(PART:"segment", "default_single", 0.0);
               else if (type == SEGMENT_TYPE_LEFT)
                 set_state(PART:"segment", "default_left", 0.0);
               else if (type == SEGMENT_TYPE_MIDDLE)
                 set_state(PART:"segment", "default_middle", 0.0);
               else if (type == SEGMENT_TYPE_RIGHT)
                 set_state(PART:"segment", "default_right", 0.0);
            }
         }
      }
      program { signal: "elm,type,segment,single"; source: "elm";
         script { set_int(seg_type, SEGMENT_TYPE_SINGLE); update_state(); }
      }
      program { signal: "elm,type,segment,left"; source: "elm";
         script { set_int(seg_type, SEGMENT_TYPE_LEFT); update_state(); }
      }
      program { signal: "elm,type,segment,middle"; source: "elm";
         script { set_int(seg_type, SEGMENT_TYPE_MIDDLE); update_state(); }
      }
      program { signal: "elm,type,segment,right"; source: "elm";
         script { set_int(seg_type, SEGMENT_TYPE_RIGHT); update_state(); }
      }
      program { signal: "elm,state,segment,normal"; source: "elm";
         script { set_int(seg_state, SEGMENT_STATE_NORMAL); update_state(); }
      }
      program { signal: "elm,state,segment,pressed"; source: "elm";
         script { set_int(seg_state, SEGMENT_STATE_PRESSED); update_state(); }
      }
      program { signal: "elm,state,segment,selected"; source: "elm";
         script { set_int(seg_state, SEGMENT_STATE_SELECTED); update_state(); }
      }
      program { signal: "elm,state,disabled"; source: "elm";
         script { set_int(seg_status, SEGMENT_STATUS_DISABLED); update_state(); }
      }
      program { signal: "elm,state,enabled"; source: "elm";
         script { set_int(seg_status, SEGMENT_STATUS_ENABLED); update_state(); }
      }
      program { signal: "elm,state,text,visible"; source: "elm";
         script { new st[31]; new Float:vl;
            get_state(PART:"elm.swallow.icon", st, 30, vl);
            if (!strcmp(st, "icononly"))
              set_state(PART:"elm.swallow.icon", "visible", 0.0);
         }
      }
      program { signal: "elm,state,text,hidden"; source: "elm";
         script { new st[31]; new Float:vl;
            get_state(PART:"elm.swallow.icon", st, 30, vl);
            if (!strcmp(st, "visible"))
              set_state(PART:"elm.swallow.icon", "icononly", 0.0);
            set_state(PART:"elm.text", "default", 0.0);
         }
      }
      program { signal: "elm,state,icon,visible"; source: "elm";
         script { new st[31]; new Float:vl;
            get_state(PART:"elm.text", st, 30, vl);
            if ((!strcmp(st, "normal")) || (!strcmp(st, "selected")))
              set_state(PART:"elm.swallow.icon", "visible", 0.0);
            else
              set_state(PART:"elm.swallow.icon", "icononly", 0.0);
         }
      }
      program { signal: "elm,state,icon,hidden"; source: "elm";
         action:  STATE_SET "default" 0.0;
         target: "elm.swallow.icon";
      }
   }
   #undef SEGMENT_TYPE_SINGLE
   #undef SEGMENT_TYPE_LEFT
   #undef SEGMENT_TYPE_MIDDLE
   #undef SEGMENT_TYPE_RIGHT
   #undef SEGMENT_STATE_NORMAL
   #undef SEGMENT_STATE_PRESSED
   #undef SEGMENT_STATE_SELECTED
   #undef SEGMENT_STATUS_ENABLED
   #undef SEGMENT_STATUS_DISABLED
}
